<template>
	<view class="address" :style="adrList.length<3?'height:'+viewHeight+'px;':''">
		<view class="list" v-if="adrList.length>0">
			<adr-item :data="item" v-for="(item,index) in adrList" :key="index">
				<u-icon name="edit-pen" size="28" @click="adrEdit(item)"></u-icon>
			</adr-item>
		</view>
		<view v-else>
			<u-empty marginTop="60%" icon='https://file.shopro.top/imgs/empty/empty_goods.png' width="260" height="260"
				text="暂无收货地址">
			</u-empty>
		</view>
		<u-loadmore :status="status" />
		<view class="foot_box">
			<u-button text="新增收货地址" type="warning" shape="circle" @click="goAddAdr"></u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				//可视高度
				viewHeight: 0,
				//请求状态
				status: 'loadmore',
				page: 0,
				adrList: [{
					id: 21,
					address: "广东 广州 白云区",
					name: "is黄某",
					phone: "13361001154",
					detail: "和兴大厦708",
					moren: 0
				}]
			}
		},
		onReady() {
			//获取屏幕高度
			uni.getSystemInfo({
				success: (res) => {
					this.viewHeight = res.windowHeight
				}
			})
		},
		onReachBottom() {
			console.log(this.page)
			if (this.page >= 3) return;
			this.status = 'loading';
			this.page = ++this.page;
			setTimeout(() => {
				this.adrList = this.adrList.concat(this.adrList)
				if (this.page >= 3) this.status = 'nomore';
				else this.status = 'loading';
			}, 2000)
		},
		methods: {
			adrEdit(data) {
				uni.navigateTo({
					url: "/pages/user/components/address/addAddress?isEdit=true"
				})
			},
			goAddAdr(data) {
				uni.navigateTo({
					url: "/pages/user/components/address/addAddress?isEdit=false"
				})
			}
		}
	}
</script>

<style lang="scss">
	.address {
		padding: 20rpx;
		background-color: #F6F6F6;
	}

	.list {
		border-radius: 20rpx;
		overflow: hidden;
	}

	.foot_box {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		background-color: #fff;
		padding: 20rpx 70rpx 80rpx;
	}
</style>